﻿<div class="row" ng-app="myScore">


    <div class="form-horizontal">
        <h4>Score Input</h4>

        <div>
            <script>
                angular.module('myScore', []).controller('ExampleController', ['$scope', function ($scope) {

                    $scope.result = [];
                    $scope.num = 0;

                    $scope.nationChanged = function () {
                        //$scope.product has your selected item in it.
                        //$scope.users = [{ name: "fsdf" }, { name: "fsdfsdfsdf" }, { name: "sdfsdfsdf" }];
                        if ($('#slNation').val() == "魏") {
                            //alert($('#slNation').val());
                            $scope.fighters = ["曹操", "司马懿", "夏侯惇", "张辽", "许褚", "郭嘉", "甄姬", "曹仁", "夏侯渊", "典韦", "荀彧", "徐晃", "曹丕", "张郃", "邓艾", "曹洪", "李典", "臧霸", "乐进"];
                        }
                        else if ($('#slNation').val() == "蜀") {
                            //alert($('#slNation').val());
                            $scope.fighters = ["刘备", "关羽", "张飞", "诸葛亮", "赵云", "马超", "黄月英", "黄忠", "魏延", "卧龙诸葛亮", "庞统", "孟获", "祝融", "刘禅", "姜维", "蒋琬&费祎", "马岱", "糜夫人", "甘夫人"];
                        }
                        else if ($('#slNation').val() == "吴") {
                            $scope.fighters = ["孙权", "甘宁", "吕蒙", "黄盖", "周瑜", "大乔", "孙尚香", "陆逊", "周泰", "小乔", "太史慈", "孙坚", "鲁肃", "张昭&张纮", "蒋钦", "徐盛", "孙策", "陈武&董袭", "丁奉"];
                        }
                        else {
                            $scope.fighters = ["华佗", "吕布", "貂蝉", "张角", "庞德", "颜良&文丑", "袁绍", "贾诩", "蔡文姬", "马腾", "孔融", "纪灵", "田丰", "潘凤", "于吉", "何太后", "董卓", "张任", "邹氏"];
                        }
                    }

                    $scope.saveRecord = function () {
                        var winner = $('#cbWinner').is(":checked");
                        var showfirst = $('#cbShowFirst').is(":checked");
                        var careerist = $('#cbCareerist').is(":checked");
                        var kills = $('#slKills').val();
                        $scope.result.push({
                            name: $("#slName").find("option:selected").text(),
                            chief: $("#slChief").find("option:selected").text(),
                            vice: $('#slVice').find("option:selected").text(),
                            win: winner,
                            show: showfirst,
                            careerist: careerist,
                            kills: kills
                        });
                        $scope.num = $scope.num + 1;

                        $('#cbWinner').prop('checked', false);
                        $('#cbShowFirst').prop('checked', false);
                        $('#cbCareerist').prop('checked', false);
                        $('#slKills').val('0');
                    };

                    $scope.submitRecord = function () {
                        var result = $scope.result;


                        $.ajax({
                            url: url + "api/scores/",
                            type: "POST",
                            data: angular.toJson($scope.result),
                            contentType: "application/json; charset=utf-8",
                            dataType: "json",
                            success: function (status) {
                                alert("Submit is done !");
                            }
                        })
                        $scope.result = [];
                        $scope.num = 0;
                    };
                }]);


            </script>

            <div ng-controller="ExampleController">
                <label>Player</label>
                <select id="slName">
                    <option>Alex</option>
                    <option>David</option>
                    <option>Elvin</option>
                    <option>Kent</option>
                    <option>Shine</option>
                    <option>Sonic</option>
                    <option>Wilbur</option>
                    <option>Tim</option>
                </select>
                <label>Nation</label>
                <select ng-model="nation" ng-change="nationChanged()" id="slNation">
                    <option>魏</option>
                    <option>蜀</option>
                    <option>吴</option>
                    <option>群</option>
                </select>
                <label>Chief</label>
                <select id="slChief" ng-model="fighter1" ng-options="f for f in fighters"></select>
                <label>Vice</label>
                <select id="slVice" ng-model="fighter2" ng-options="f for f in fighters"></select>

                <label>Kills</label>
                <select id="slKills">
                    <option>0</option>
                    <option>1</option>
                    <option>2</option>
                    <option>3</option>
                    <option>4</option>
                    <option>5</option>
                    <option>6</option>
                    <option>7</option>
                </select>
                <label>Winner</label>
                <input type="checkbox" id="cbWinner" />
                <label>Show First</label>
                <input type="checkbox" id="cbShowFirst" />
                <label>Careerist</label>
                <input type="checkbox" id="cbCareerist" />


                <button class="primary" ng-click="saveRecord()">Save</button>
                <button class="primary" ng-click="submitRecord()">Submit</button>
                @*  <button class="primary" ng-click="testing()">Testing</button>*@
                <label>to be submited record : {{num}}</label>

            </div>

        </div>

    </div>
</div>